package com.ztgf.shopping.api.client.epg;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgAggregationCategoryBO;
import com.ztgf.shopping.models.bo.epg.EpgShopSectionCommodityRelationBO;
import com.ztgf.shopping.models.dto.epg.EpgAggregationCategoryDTO;
import com.ztgf.shopping.models.vo.epg.EpgAggregationCategoryCommodityRelationVO;
import com.ztgf.shopping.models.vo.epg.EpgAggregationCategoryVO;
import com.ztgf.shopping.models.vo.epg.EpgShopSectionCommodityRelationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.epg.IEpgAggregationCategoryCommodityRelationService;
import com.ztgf.shopping.models.bo.epg.EpgAggregationCategoryCommodityRelationBO;
import com.ztgf.shopping.models.dto.epg.EpgAggregationCategoryCommodityRelationDTO;

import java.util.List;

/**
 * 聚合页分类商品控制器
 *
 * @author YUE
 * @Date 2020-06-04 15:38:23
 */

@RestController
@RequestMapping("/api/epgAggregationCategoryCommodityRelation")
@Slf4j
@Api(value = "EpgAggregationCategoryCommodityRelationApiController",tags = "聚合页分类商品Api接口")
public class EpgAggregationCategoryCommodityRelationApiController {

    @DubboReference
    private IEpgAggregationCategoryCommodityRelationService epgAggregationCategoryCommodityRelationService;

    @ApiOperation(value = "分类栏目商品表",notes = "分类栏目商品表")
    @PostMapping("/getListByCategoryId")
    public Result<List<EpgAggregationCategoryCommodityRelationVO>> getListBySectionId(Long categoryId){
        EpgAggregationCategoryCommodityRelationBO epgAggregationCategoryCommodityRelationBO = new EpgAggregationCategoryCommodityRelationBO();
        epgAggregationCategoryCommodityRelationBO.setCategoryId(categoryId);
        List<EpgAggregationCategoryCommodityRelationVO> epgShopSectionCommodityRelationVOList = epgAggregationCategoryCommodityRelationService.getBySelectSectionCommodityRelationInfo(epgAggregationCategoryCommodityRelationBO);
        return new Result<>(epgShopSectionCommodityRelationVOList);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgAggregationCategoryCommodityRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        EpgAggregationCategoryCommodityRelationDTO dto = epgAggregationCategoryCommodityRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "聚合页分类商品列表",notes = "聚合页分类商品列表")
    @PostMapping("/queryPageList")
    public Result<Page<EpgAggregationCategoryCommodityRelationDTO>> queryPageList(EpgAggregationCategoryCommodityRelationBO bo){
       Wrapper<EpgAggregationCategoryCommodityRelationDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<EpgAggregationCategoryCommodityRelationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = epgAggregationCategoryCommodityRelationService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
